#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# author: maxiao
# file_name: 1030.py
# date: 2022/10/30 12:09
# description: 测试 + 与join拼接字符的效率

import time


count=10000000
def test_add():
    a = ''
    start = time.time()
    for i in range(count):
        a += '6'
    print(len(a))
    end = time.time()
    print("使用+拼接字符串用时:{:.3f}秒".format(end - start))


def test_join():
    b = []
    start = time.time()
    for i in range(count):
        b.append('6')
    result = ''.join(b)
    print(len(result))
    end = time.time()
    print("使用join拼接字符串用时:{:.3f}秒".format(end - start))

print(f"拼接{count}个字符所需的时间如下")
test_add()
print('-' * 50)
test_join()
